#!/bin/bash

BACKUP_NAME="backup.tar"
BACKUP_DATE=`date +%Y%m%d_%H%M%S`

sudo rm -rf /home/${USER}/.cache/* /home/${USER}/.ros/* /var/cache/* /var/log/* /tmp/*



if [ -a /${BACKUP_NAME} ]; then
    rm -rf /${BACKUP_NAME}
    echo "rm -rf ${BACKUP_NAME} done"
fi
# c-打包，x-解压
# v-可视，p-保留权限
# z-调用gzip压缩，j-调用bzip2压缩
# f-接file_name
# C-接解压的目录
# tar -cvpzf ${BACKUP_NAME}       \
sudo tar -cpvf ${BACKUP_NAME}         \
    --exclude=/dev             \
    --exclude=/proc             \
    --exclude=/sys              \
    --exclude=/run              \
    --exclude=/mnt              \
    --exclude=/media            \
    --exclude=/lost+found       \
    --exclude=/swapfile         \
    --exclude=${BACKUP_NAME}    \
    --exclude=/home/${USER}/Downloads/*    \
    --exclude=/home/${USER}/Programing/*   \
    --exclude=/home/${USER}/SoftWare/*     \
    --exclude=/var/lib/docker/overlay2        \
    --exclude=/home/${USER}/.local/share/docker/overlay2 \
    /

sudo chown ${USER}:${USER} ${BACKUP_NAME}
mv ${BACKUP_NAME} ${BACKUP_DATE}-${BACKUP_NAME} 

echo "if need compress file"
echo "pigz *.tar" 
